<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Response;
use App\Http\Controllers\AuController;
use App\Libs\Base;
use View, DB;
class ImageController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function getIndex()
    {
        return View::make('images.upload');
    }

    public function getUpload()
    {
        $listCategory = config('app.categories');
        return View::make('images.upload', ['listCategory' => $listCategory]);
    }
    public function postUpload(Request $request)
    {
        echo json_encode(array('code' => 10200, 'imgUrl' => 'http://7xogjk.com1.z0.glb.clouddn.com/14505417106.png'));
        die();
        $fileImg = $request->file('imgFile');
        $path = $fileImg->getPathName();
        $mimiType = $fileImg->getMimeType();
        switch($mimiType) {
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/ejpeg':
                $prefix = 'jpg';
                break;
            case 'image/png':
                $prefix = 'png';
                break;
            default:
                $prefix = '';
                break;
        }
        if (empty($prefix)) {
            // 文件格式错误
            echo json_encode(array('code' => 10400));
            die();
        }
        $name = time() . rand(0, 9) . '.' . $prefix;
        $res = Base::uploadImg($fileImg, $name);
        if ($res[1]) {
            // 上传图片失败
            echo json_encode(array('code' => 10401));
            die();
        }
        $urlPrefix = config('app.qiniu_url');
        echo json_encode(array('code' => 10200, 'imgUrl' => $urlPrefix . $name));
        die();
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
